#include "MatrixKeyBoard.h"
#include "LCD1602.h"
#include "DelayTime.h"

void main()
{
	int count = 0;
	int sum = 0;
	int ret = 0;
	int passwd = 1234;
	LCD_Init();
	LCD_ShowString(1,1,"PassWord:");
	
	while(1)
	{
			// 先LCD1602只显示4位数
			ret = GetKeyBoard();
			if(ret > 0 && ret < 10) // 输入
			{
				// 限制输入次数
				
				if(count < 4)
				{
					sum = sum * 10 + ret;
					LCD_ShowNum(2,1,sum,4);
					LCD_ShowString(1,14,"   ");
					count++;	
				}
				
			}
			else if(ret == 10) // 确认
			{
				LCD_ShowNum(2,1,sum,4);
				if(sum == passwd)
				{
					LCD_ShowString(1,14,"OK ");
				}
				else
				{
					LCD_ShowString(1,14,"ERR");
				}
				count = 0;
				sum = 0;
			}
			else if(ret == 11) // 取消
			{
				count = 0;
				sum = 0;
			}

	}
}